package com.pro.common.api.user.task.model.db;

import com.baomidou.mybatisplus.annotation.TableField;
import com.pro.common.api.model.BaseUserModel;
import com.pro.common.api.model.auth.IUserOrderClass;
import com.pro.common.api.model.auth.IUserRecordClass;
import com.pro.common.api.model.auth.subaccount.IOpenSubQuery;
import com.pro.common.api.user.task.enums.EnumUserTaskStatus;
import com.pro.common.api.user.task.model.base.IUserTaskCreate;
import com.pro.framework.javatodb.annotation.JTDField;
import com.pro.framework.javatodb.annotation.JTDTable;
import com.pro.framework.javatodb.constant.JTDConst;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

@Data
@Schema(description = "用户任务")
@JTDTable(entityId = 20001, sequences = {
//        "UNIQUE KEY uk_userId_taskType_referenceId (`user_id`, `task_type`, `reference_id`)"
})
public class UserTask extends BaseUserModel implements IUserRecordClass, IUserTaskCreate, IOpenSubQuery {

    /**
     * ${@link  com.pro.baoyi.common.api.enums.EnumUserTaskTypeBaoyi}
     */
    @Schema(description = "处理类型")
    private String taskType;

    @Schema(description = "关联对象ID")
    @JTDField(notNull = JTDConst.EnumFieldNullType.can_null, defaultValue = "NULL")
    private String referenceCode;
    @Schema(description = "关联对象ID")
    @JTDField(notNull = JTDConst.EnumFieldNullType.can_null, defaultValue = "NULL")
    private Long referenceId;

    @Schema(description = "名称")
    private String taskName;
    @Schema(description = "子名称")
    private String taskSubName;
    @Schema(description = "子名称2")
    private String taskSubName2;

    @Schema(description = "任务附加信息(JSON)")
    @JTDField(type = JTDConst.EnumFieldType.text)
    private String metaInfo;

    @Schema(description = "处理状态")
    @JTDField(type = JTDConst.EnumFieldType.int_, defaultValue = "0", entityClassKey = "value")
    private EnumUserTaskStatus status;

    @Schema(description = "当前执行到第几步")// 刚创建就是第1步骤
    private Integer currentStep;
    @Schema(description = "总共几步")
    private Integer totalSteps;

    @Schema(description = "失败原因")
    @JTDField(mainLength = 500)
    private String errorMsg;

//    @Schema(description = "任务优先级")
//    private Integer priority;
//
//    @Schema(description = "任务整体重试次数")
//    private Integer retryCount;

    @Schema(description = "任务完成时间")
    private LocalDateTime finishedTime;

    @Schema(description = "下级用户Id")
    private Long createBy;

    @Schema(description = "步骤")
    @TableField(exist = false)
    private List<UserTaskStep> userTaskSteps;

}
